<template>
  <div class="app-container mod-hot-search">
    <!-- 搜索相关区域 -->
    <div class="filter-container">
      <el-form :inline="true" :model="pageQuery" class="demo-form-inline">
        <el-form-item label="店铺ID">
          <el-input
            v-model="pageQuery.barCounterShopId"
            size="mini"
            placeholder="请输入店铺ID"
          />
        </el-form-item>
        <el-form-item label="吧台编号">
          <el-input
            v-model="pageQuery.barCounterId"
            size="mini"
            placeholder="请输入吧台编号"
          />
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="pageQuery.createTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click="getPage()"
            >查询</el-button
          >
          <el-button
            size="mini"
            icon="el-icon-delete"
            @click="clearSearchInfo()"
            >清空</el-button
          >
        </el-form-item>
      </el-form>
      <el-button
        size="mini"
        icon="el-icon-plus"
        type="primary"
        class="filter-item"
        @click="addOrUpdateHandle()"
        >新增</el-button
      >
    </div>
    <!-- 列表相关区域 -->
    <el-table
      v-loading="pageLoading"
      :data="pageVO.list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <!-- 店铺ID -->
      <el-table-column label="店铺ID" prop="barCounterShopId" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.barCounterShopId }}</span>
        </template>
      </el-table-column>
      <!-- 店铺名称 -->
      <el-table-column label="店铺名称" prop="shopName" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.shopName }}</span>
        </template>
      </el-table-column>
      <!-- 关联吧台编号 -->
      <el-table-column label="关联吧台编号" prop="barCounterNumber" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.barCounterNumber }}</span>
        </template>
      </el-table-column>
      <!-- 投放区域 -->
      <el-table-column
        label="投放区域"
        prop="barCounterRegion"
        width="250"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.barCounterRegion }}</span>
        </template>
      </el-table-column>
      <!-- 设备数量 -->
      <el-table-column label="设备数量" prop="seq" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.seq }}</span>
        </template>
      </el-table-column>
      <!-- 人员数量 -->
      <el-table-column label="人员数量" prop="seq" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.seq }}</span>
        </template>
      </el-table-column>
      <!-- 创建时间 -->
      <el-table-column label="创建时间" prop="createTime" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('table.actions')"
        align="center"
        width="200"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button
            type="primary"
            size="mini"
            @click="addOrUpdateHandle(row.barCounterShopId)"
          >
            编辑
          </el-button>
          <el-button
            type="primary"
            size="mini"
            @click="goDetail(row)"
          >
            查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页条 -->
    <pagination
      v-show="pageVO.total > 0"
      :total="pageVO.total"
      :page.sync="pageQuery.pageNum"
      :limit.sync="pageQuery.pageSize"
      @pagination="getPage()"
    />
    <Detail v-if="detailVisible" ref="detailS" />
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getPage()"
    />
  </div>
</template>
<script>
import permission from "@/directive/permission/index.js";
import Pagination from "@/components/Pagination";
import AddOrUpdate from "./add-or-update.vue";
import * as api from "@/api/shop/index";
import Detail from "./detail.vue";
export default {
  name: "",
  components: { Pagination, Detail, AddOrUpdate },
  directives: { permission },
  data() {
    return {
      detailVisible: false,
      addOrUpdateVisible: false,
      // 查询的参数
      pageQuery: {
        pageSize: 10,
        pageNum: 1,
        title: null,
        content: null,
        status: null,
        shopId: null,
      },
      // 返回参数
      pageVO: {
        list: [], // 返回的列表
        total: 0, // 一共多少条数据
        pages: 0, // 一共多少页
      },
      // loading
      pageLoading: true,
    };
  },
  mounted() {
    this.getPage();
  },
  methods: {
    addOrUpdateHandle(barCounterShopId) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(barCounterShopId)
      })
    },
    getPage() {
      this.pageLoading = true;
      api.getPage({ ...this.pageQuery }).then((pageVO) => {
        this.pageVO = pageVO;
        this.pageLoading = false;
      });
    },
    goDetail(data) {
      this.detailVisible = true;
      this.$nextTick(() => {
        this.$refs.detailS.init(data);
      });
    },

    clearSearchInfo() {
      // 若请求参数某项没值，则不传此参数
      this.pageQuery.pageNum = 1;
      this.pageQuery.pageSize = 10;
      this.pageQuery.title = null;
      this.pageQuery.content = null;
      this.pageQuery.status = null;
      this.pageQuery.shopId = null;
      this.getPage();
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.mod-hot-search {
  .el-form--inline {
    .el-form-item {
      margin-right: 20px;
    }
  }
}
</style>
  